
/**
 * 
 */
package com.zsrt.day20170417.ch02.dao.impl;

import com.zsrt.day20170417.ch02.Animal;
import com.zsrt.day20170417.ch02.AnimalShop;
import com.zsrt.day20170417.ch02.dao.AnimalDao;

/**
 * @author jmj
 * @date 2017年4月17日
 * @time 上午11:56:39
 */
public  class AnimalDaoImpl implements AnimalDao{
	
	
	/**
	 * 增加一个动物
	 */
	@Override
	public boolean addAnimal(AnimalShop  animalShop, Animal animal) {
		boolean flag = false;
		
		
		//判断笼子是否满了
		int count = 0;
		
		Animal[] lz = animalShop.getLz();
		for(int index = 0;index<10;index++){
			
			Animal dw = lz[index];
			if(dw != null){
				count++;
				
			}else{
				break;
			}
			
		}
		
		if(count<10){
			flag = true;
			
			lz[count]=  animal;             
		}else{
			System.out.println("笼子已满，恕不接待。。。");
		}
		
		
		
		return flag;

	}
	
	
	@Override
	public boolean addSomeAnimal(AnimalShop animalShop, Animal[] animal) {
		boolean flag = false;
		
		
		//判断笼子是否满了
		int count = 0;
		
		Animal[] lz = animalShop.getLz();
		for(int index = 0;index<10;index++){
			
			Animal dw = lz[index];
			if(dw != null){
				count++;	
			}else{
				break;
			}
		}
		
		//笼子可以装下
		if(count <=lz.length -animal.length){
			flag = true;
			for(int i=0;i<animal.length;i++){
				
				lz[count+i]=animal[i];
			}
			
		}else{
			System.out.println("位置不够，请选择其他店");
		}
		
		return flag;
	}

}
